﻿using System.Web.Mvc;
using Uber.Core.Service;

namespace Uber.WebUI.Controllers
{
    [Authorize(Roles = "admin")]
    public class FillPayRequestController : Controller
    {
        private readonly IFillPayRequests s;


        public FillPayRequestController(IFillPayRequests s)
        {
            this.s = s;
        }

        public ActionResult Index(int? page)
        {
            return View(s.GetPage(page ?? 1, 5));
        }

        public ActionResult Details(long id)
        {
            var o = s.Get(id);
            if (o.Filled) return Content("this is filled already");
            return View(o);
        }

        [HttpPost]
        public ActionResult Details(long id, string transactionId, string token)
        {
            while (true)
            {
                if(token != "fill") ModelState.AddModelError("_FORM", "word");
                if(!ModelState.IsValid) break;
                if (s.Fill(id, transactionId)) return RedirectToAction("Index");
                ModelState.AddModelError("_FORM", "wasn't saved");
                break;
            }
            return View(s.Get(id));
        }
    }
}